package com.cqw.ftp.config;


import com.cqw.ftp.ftp.FTPClientFactory;
import com.cqw.ftp.ftp.FTPClientHelper;
import com.cqw.ftp.ftp.FTPClientPool;
import com.cqw.ftp.ftp.FtpPoolConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.nio.charset.Charset;
import java.util.List;

/**
 * 
 * @date 配置文件
 *
 */
@Configuration
public class MyWebAppConfigurer extends WebMvcConfigurationSupport {

	@Bean
	public FTPClientPool getFTPClientPool() {
		return new FTPClientPool(getFTPClientFactory());
	}
	@Bean(name = "ftpClientHelper")
	public FTPClientHelper getFTPClientHelper() {
		return new FTPClientHelper();
	}
	@Bean
	public FTPClientFactory getFTPClientFactory() {
		FTPClientFactory factory = new FTPClientFactory();
		factory.setFtpPoolConfig(getFtpPoolConfig());
		return factory;
	}
	@Bean
	public FtpPoolConfig getFtpPoolConfig() {
		return new FtpPoolConfig();
	}


	//解决编码问题
	@Bean
	public HttpMessageConverter<String> responseBodyConverter() {
		StringHttpMessageConverter converter = new StringHttpMessageConverter(
				Charset.forName("UTF-8"));
		return converter;
	}

	@Override
	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
		super.configureMessageConverters(converters);
		converters.add(responseBodyConverter());
	}

	@Override
	public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
		configurer.favorPathExtension(false);
	}
}
